using System.ComponentModel;

namespace ImageCSharp.Core.Models
{
    /// <summary>
    /// 工具类型枚举
    /// </summary>
    public enum ToolType
    {
        [Description("选择工具")]
        Selection,
        
        [Description("绘图工具")]
        Drawing,
        
        [Description("测量工具")]
        Measurement,
        
        [Description("变换工具")]
        Transform,
        
        [Description("滤镜工具")]
        Filter,
        
        [Description("魔术棒工具")]
        MagicWand,
        
        [Description("橡皮擦工具")]
        Eraser
    }

    /// <summary>
    /// 工具基类
    /// </summary>
    public abstract class Tool
    {
        public string Name { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public ToolType Type { get; set; }
        public string IconPath { get; set; } = string.Empty;
        public bool IsActive { get; set; }
        public Dictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();
        public SelectionMode Mode { get; set; }
        public int Feather { get; set; }
        public bool AntiAlias { get; set; }
        public int BrushSize { get; set; }
        public System.Drawing.Color Color { get; set; }
        public float Opacity { get; set; }
        public BrushMode BrushMode { get; set; }
    }

    /// <summary>
    /// 选择工具
    /// </summary>
    public class SelectionTool : Tool
    {
        public SelectionTool()
        {
            Type = ToolType.Selection;
            Properties.Add("Mode", SelectionMode.Rectangle);
            Properties.Add("Feather", 0);
            Properties.Add("AntiAlias", true);
        }

        public SelectionMode Mode 
        { 
            get => (SelectionMode)Properties["Mode"]; 
            set => Properties["Mode"] = value; 
        }

        public int Feather 
        { 
            get => (int)Properties["Feather"]; 
            set => Properties["Feather"] = value; 
        }

        public bool AntiAlias 
        { 
            get => (bool)Properties["AntiAlias"]; 
            set => Properties["AntiAlias"] = value; 
        }
    }

    /// <summary>
    /// 绘图工具
    /// </summary>
    public class DrawingTool : Tool
    {
        public DrawingTool()
        {
            Type = ToolType.Drawing;
            Properties.Add("BrushSize", 5);
            Properties.Add("Color", System.Drawing.Color.Black);
            Properties.Add("Opacity", 1.0f);
            Properties.Add("Mode", BrushMode.Normal);
            Properties.Add("IsEraser", false);
        }

        public int BrushSize 
        { 
            get => (int)Properties["BrushSize"]; 
            set => Properties["BrushSize"] = value; 
        }

        public SixLabors.ImageSharp.Color Color 
        { 
            get => (SixLabors.ImageSharp.Color)Properties["Color"]; 
            set => Properties["Color"] = value; 
        }

        public float Opacity 
        { 
            get => (float)Properties["Opacity"]; 
            set => Properties["Opacity"] = value; 
        }

        public BrushMode Mode 
        { 
            get => (BrushMode)Properties["Mode"]; 
            set => Properties["Mode"] = value; 
        }

        public bool IsEraser 
        { 
            get => (bool)Properties["IsEraser"]; 
            set => Properties["IsEraser"] = value; 
        }
    }

    /// <summary>
    /// 橡皮擦工具
    /// </summary>
    //public class EraserTool : DrawingTool
    //{
    //    public EraserTool()
    //    {
    //        Name = "橡皮擦";
    //        Description = "橡皮擦工具";
    //        IsEraser = true;
    //        Color = System.Drawing.Color.White; // 橡皮擦颜色通常为背景色
    //    }
    //}

    /// <summary>
    /// 选择模式
    /// </summary>
    public enum SelectionMode
    {
        Rectangle,
        Ellipse,
        Polygon,
        MagicWand,
        Lasso,
        ColorRange
    }

    /// <summary>
    /// 画笔模式
    /// </summary>
    public enum BrushMode
    {
        Normal,
        Multiply,
        Screen,
        Overlay,
        SoftLight,
        HardLight
    }
}